package {{apiPackage}};

import {{modelPackage}}.*;

{{#annotationImport}}import {{annotationImport}};
{{/annotationImport}}

{{#imports}}import {{import}};
{{/imports}}

import cn.featherfly.common.http.HttpMethod;
import cn.featherfly.easyapi.*;
import cn.featherfly.easyapi.client.*;

import java.util.List;
import java.util.Map;
import java.util.HashMap;

{{#operations}}
/**
 * the {{baseName}} API
 */
public class {{classname}} {

    protected HttpRequest httpRequest;

    protected DomainManager domainManager;

    public {{classname}}() {
        this(ApiUtils.getDefaultHttpRequest({{classname}}.class), ApiUtils.getDefaultDomainManager());
    }

    public {{classname}}(HttpRequest httpRequest, DomainManager domainManager) {
        this.httpRequest = httpRequest;
        this.domainManager = domainManager;
    }

    {{#operation}}
    /**
     * {{{summary}}}.
     * {{{notes}}}.
     */
    public ApiInvoker<{{#returnType}}{{{returnType}}}Response{{/returnType}}{{^returnType}}EmptyDataResult{{/returnType}}> {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>requestParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){
        final String path = domainManager.getDomain("{{domainGroup}}")
               + "{{apiPath}}{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{baseName}}" + "\\}", {{paramName}} + ""){{/pathParams}};
        Map<String, String> headers = new HashMap<>();
        {{#bodyParams}}return new HttpSendBodyApiInvoker<{{#returnType}}{{{returnType}}}Result{{/returnType}}{{^returnType}}EmptyDataResult{{/returnType}}>(HttpMethod.{{httpMethod}}, path, {{paramName}}, headers, {{#returnType}}{{{returnType}}}Result{{/returnType}}{{^returnType}}EmptyDataResult{{/returnType}}.class, httpRequest);{{/bodyParams}}
        {{^bodyParams}}Map<String, java.io.Serializable> params = new HashMap<>();
        {{#allParams}}{{>setParams}}
        {{/allParams}}return new HttpFormParamApiInvoker<{{#returnType}}{{{returnType}}}Result{{/returnType}}{{^returnType}}EmptyDataResult{{/returnType}}>(HttpMethod.{{httpMethod}}, path, params, headers, {{#returnType}}{{{returnType}}}Result{{/returnType}}{{^returnType}}EmptyDataResult{{/returnType}}.class, httpRequest);{{/bodyParams}}
    }
    {{/operation}}
}
{{/operations}}
